/**
 * COPYRIGHT. Harry Wu 2011. ALL RIGHTS RESERVED.
 * Project: just
 * Author: Harry Wu <harrywu304@gmail.com>
 * Created On: Jun 14, 2011 9:37:24 AM
 *
*/ 
package org.justframework.api.connector;

import java.util.HashMap;
import java.util.Map;

import org.justframework.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * client factory
 *
 */
public class ClientConnectorFactory {
	
	/**
	 * logger
	 */
	private static Logger logger = LoggerFactory.getLogger(ClientConnectorFactory.class);
	
	
	/**
	 * clients
	 */
	private static Map<String, ClientConnector> clients = new HashMap<String, ClientConnector>();;
	
	/**
	 * get client connector according schema
	 * @param uri
	 * @return client connector
	 */
	public static ClientConnector getClientConnector(String klassName){
		if(StringUtil.isNullOrBlank(klassName)){
			return null;
		}
		ClientConnector client = clients.get(klassName);
		if(client == null){
			try {
				Class clientKlass = Class.forName(klassName);
				client = (ClientConnector) clientKlass.newInstance();
				clients.put(klassName, client);	
			} catch (Exception e) {
				logger.error("Create Client by concrete class {} fail",klassName,e);
			}	
		}
		return client;
	}
	
}
